﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2Net8Configuration.Customer
{
    public class TextConfigurationProvider : ConfigurationProvider
    {
        TextConfigurationSource source;
        public TextConfigurationProvider(TextConfigurationSource textConfigurationSource)
        {
            source = textConfigurationSource;
        }
        public override void Load()
        {
            if (!File.Exists(source.FilePath))
            {
                throw new Exception();
            }

            var fileTexts = File.ReadAllLines(source.FilePath);
            // 储存内容
            Dictionary<string, string> data = new Dictionary<string, string>();
            // 读取文本所有内容
            foreach (var fileText in fileTexts)
            {
                // 解析 遍历
               string[] context = fileText.Split('=');
                if (context.Count() > 1)
                {
                    data[context[0]] = context[1];
                }
            }
            Data = data;
        }
    }
}
